<?php

include('Model/clsketnoi.php');

function hienthitimkiem()
{
    $tukhoa = $_POST['timkiem'];
    $limit = 12; //gioi han so row trong 1 trang

    $page = isset ( $_GET["page"] ) ? intval ( $_GET["page"] ) : 1; //get trang hien thi

    $page_start = ( $page - 1 ) * $limit;
    $page_end = $page * $limit;

    $query = mysql_query("SELECT madausach, ten, hinh, giabia from tbldausach where ten like '%$tukhoa%'",dbketnoi());

    $number_of_page = ceil(mysql_num_rows($query)/$limit); // lay tong row

    if ($number_of_page > 1)
    {
        $list_page = " <td> Trang: </td>";

        for ( $i = 1; $i <= $number_of_page; $i++ )
            {
            if ( $i == $page )
            {
                $list_page .= " <td>[ <b>{$i}</b> ]</td> ";
           
            }
            else
            {
                $list_page .= "<td><a href='giaodientimkiem.php?page={$i}'> {$i} </a></td>";
                
            }
        }
    }

    $i = 0;
    while ( $result = mysql_fetch_array ( $query ) )
    {
        if ( $i >= $page_start )
        {
           echo "<div style='float: left; width: 33%;'>
            <table>
                <tr>
                    <td><img height='200' width='150' src='upload/hinhsach/".$result['hinh']."'/></td>
                </tr>
                <tr>
                    <td>Tên Sách: ".$result['ten']."</td>
                </tr>
                <tr>
                    <td>Giá Bìa: ".$result['giabia']." VNĐ</td>
                </tr>
            </table>
        
            </div>";
        }

        $i++;

        if ($i >= $page_end)
        {
            break;
        }
    }
    echo "</table></br>";
    echo $list_page;
}



?>